package dao;
// default package

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import pojobean.Members;

/**
 * A data access object (DAO) providing persistence and search support for
 * Members entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see .Members
 * @author MyEclipse Persistence Tools
 */

public class MembersDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(MembersDAO.class);
	// property constants
	public static final String UNAME = "uname";
	public static final String UPASS = "upass";
	public static final String UTYPE = "utype";
	public static final String TNAME = "tname";
	public static final String SEX = "sex";
	public static final String AGE = "age";
	public static final String TEL = "tel";
	public static final String ADDRS = "addrs";
	public static final String FILENAME = "filename";
	public static final String QQ = "qq";
	public static final String BEI = "bei";
	public static final String SAVETIME = "savetime";

	protected void initDao() {
		// do nothing
	}

	public void save(Members transientInstance) {
		log.debug("saving Members instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Members persistentInstance) {
		log.debug("deleting Members instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Members findById(java.lang.Integer id) {
		log.debug("getting Members instance with id: " + id);
		try {
			Members instance = (Members) getHibernateTemplate().get("Members",
					id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Members instance) {
		log.debug("finding Members instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Members instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Members as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUname(Object uname) {
		return findByProperty(UNAME, uname);
	}

	public List findByUpass(Object upass) {
		return findByProperty(UPASS, upass);
	}

	public List findByUtype(Object utype) {
		return findByProperty(UTYPE, utype);
	}

	public List findByTname(Object tname) {
		return findByProperty(TNAME, tname);
	}

	public List findBySex(Object sex) {
		return findByProperty(SEX, sex);
	}

	public List findByAge(Object age) {
		return findByProperty(AGE, age);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findByAddrs(Object addrs) {
		return findByProperty(ADDRS, addrs);
	}

	public List findByFilename(Object filename) {
		return findByProperty(FILENAME, filename);
	}

	public List findByQq(Object qq) {
		return findByProperty(QQ, qq);
	}

	public List findByBei(Object bei) {
		return findByProperty(BEI, bei);
	}

	public List findBySavetime(Object savetime) {
		return findByProperty(SAVETIME, savetime);
	}

	public List findAll() {
		log.debug("finding all Members instances");
		try {
			String queryString = "from Members";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Members merge(Members detachedInstance) {
		log.debug("merging Members instance");
		try {
			Members result = (Members) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Members instance) {
		log.debug("attaching dirty Members instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Members instance) {
		log.debug("attaching clean Members instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static MembersDAO getFromApplicationContext(ApplicationContext ctx) {
		return (MembersDAO) ctx.getBean("MembersDAO");
	}
}